import HTMLParser
import urllib
import re
import string


urlString = "http://www.ixor.se/members/"
urlText = []
pathOut = "ixp_members.txt"


class Parse170 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "pre":
            self.check = True
    
    def handle_data (self, data):
        if self.check == True:
            # separo i dati mantenendo in data i separatori (pattern tra parentesi)
            data = re.split("(AS\d+)", data)
            for i in data:
                # considero solo gli elementi di data che sono i separatori, ossia ASN
                if re.match("^AS\d+$", i):
                    i = string.lstrip(i, "AS")
                    if i not in urlText:
                        urlText.append(i)
            self.check = False


lparser = Parse170()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "170 %s" % item
fileOut.close()